﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for SqlConnection
/// </summary>
public class clsConnection
{
    private string _sName;

    public string SName
    {
        get { return _sName; }
        set { _sName = value; }
    }
    private string _dbName;

    public string DbName
    {
        get { return _dbName; }
        set { _dbName = value; }
    }
    private bool _iSecurity;

    public bool ISecurity
    {
        get { return _iSecurity; }
        set { _iSecurity = value; }
    }
    private string _uid;

    public string Uid
    {
        get { return _uid; }
        set { _uid = value; }
    }
    private string _pwd;

    public string Pwd
    {
        get { return _pwd; }
        set { _pwd = value; }
    }
	public clsConnection()
	{
        _sName = "";
        _dbName = "";
        _iSecurity = true;
        _uid = "";
        _pwd = "";
	}
    public clsConnection(string sName, string dbName, bool iSecurity, string uid = "", string pwd = "")
    {
        _sName = sName;
        _dbName = dbName;
        _iSecurity = iSecurity;
        _uid = uid;
        _pwd = pwd;
    }
    public string getConnectionString()
    {
        SqlConnectionStringBuilder strConn = new SqlConnectionStringBuilder();
        strConn.DataSource = SName;
        strConn.InitialCatalog = DbName;
        if (ISecurity)
            strConn.IntegratedSecurity = ISecurity;
        else
        {
            strConn.UserID = Uid;
            strConn.Password = Pwd;
        }
        //Tra ve chuoi ket noi
        return strConn.ConnectionString;
    }
}